<?php
include("connection.php");
include("header.php");

?>

<form action="userreg.php?action=save" method="post">
<table width="352" border="0" cellpadding="0" bgcolor="#FFD8B0" cellspacing="0" bordercolor="#000000">
  <tr>
  <td colspan="2"><div align="center"><h1>Register</h1></div></td>
  </tr>
  <tr>
    <td width="159"><h4>First name</h4> </td>
    <td width="187"><label>
      <div align="left">
        <input type="text" name="fname">
        </div>
    </label></td>
  </tr>
  <tr>
    <td><h4>Last name</h4> </td>
    <td><label>
      <div align="left">
        <input type="text" name="lname">
        </div>
    </label></td>
  </tr>
  <tr>
    <td><h4>E-mail</h4></td>
    <td><div align="left">
      <input type="text" name="email">
    </div></td>
  </tr>
  <tr>
    <td><h4>Password</h4></td>
    <td><div align="left">
      <input type="password" name="password">
    </div></td>
  </tr>
  <tr>
    <td><h4>Confirmpassword</h4></td>
    <td><div align="left">
      <input type="password" name="password1">
    </div></td>
  </tr>
  <tr>
    <td><h4>NIC number</h4></td>
    <td><div align="left">
      <input type="text" name="nic">
    </div></td>
  </tr>
  <tr>
    <td><h4>Phone number</h4></td>
    <td><div align="left">
      <input type="text" name="phoneno">
    </div></td>
  </tr>
  <tr>
    <td><h4>Address</h4></td>
    <td><div align="left">
      <input type="text" name="address">
    </div></td>
  </tr>
  <tr>
    <td><h4>Gender</h4></td>
    <td><input type="radio" value="Male" name="note">Male<input type="radio" value="Female" name="note">Female </td>
  </tr>
   <tr>
    <td><h4>Usertype</h4></td>
    <td><input type="radio" value="user" name="usergroup">User<input type="radio" value="eventmanager" name="usergroup">Manager <input type="radio" value="admin" name="usergroup">Admin</td>
	</tr>
  
  
  <tr>
    <td colspan="2"><label>
    <div align="center">
      <input type="submit" name="Submit" value="Submit">
    </div>
    </label></td>
    </tr>
</table>

</form>
<?php
if($_GET["action"]=="save")
{
$fname=$_POST["fname"];
$lname=$_POST["lname"];
$email=$_POST["email"];
$password=$_POST["password"];
$password1=$_POST["password1"];
$phoneno=$_POST["phoneno"];
$nic=$_POST["nic"];
$address=$_POST["address"];
$gender=$_POST["note"];
$usergroup=$_POST["usergroup"];
if($fname=="" || $lname=="")
{
echo"name is blank";
}
else if(strpos($email,"@")<1)
{
echo"wrong email";
}
else if(strlen($nic)<>10)
{
echo"wrong nic number";
}
else
{
if($password==$password1)
{
mysql_query("INSERT INTO users(fname,lname,email,password,phoneno,nic,address,note,usergroup)VALUES('$fname','$lname','$email','$password1','$phoneno','$nic','$address','$note','$usergroup')")or
die(mysql_error());

echo"regestion success";

} else {

echo "check passwords";
}

}
}


include("footer.php");
?>